package com.huawang.mdesign.model.service.controller;

import com.huawang.mdesign.model.service.dto.*;
import com.huawang.mdesign.model.service.vo.BaseResponse;
import com.huawang.business.constants.ParamErrorConstants;
import com.huawang.mdesign.model.service.inter.SequenceService;
import com.huawang.business.vo.ModelResultVo;
import com.huawang.mdesign.model.service.vo.StateInvariantPopupVo;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * @Description 序列图Controller
 * @Date 2022/5/18
 * @Author baibf
 */
@Tag(name = "序列")
@RestController
@RequestMapping("/sequence")
@Validated
public class SequenceController {

    private final SequenceService sequenceService;

    public SequenceController(SequenceService sequenceService) {
        this.sequenceService = sequenceService;
    }

    @Operation(summary = "拖拽模型到序列图上")
    @PostMapping("/dragElementToSequenceDiagram")
    public BaseResponse<ModelResultVo> dragElementToSequenceDiagram(
            @RequestBody DragElementToSequenceDiagramDTO dragElementToSequenceDiagramDto) {
        return BaseResponse.success(sequenceService.dragElementToSequenceDiagram(dragElementToSequenceDiagramDto));
    }

    @Operation(summary = "创建状态常量时是否弹窗")
    @GetMapping("/createStateInvariantIsPopup")
    public BaseResponse<StateInvariantPopupVo> createStateInvariantIsPopup(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                                           @NotBlank(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId) {
        return BaseResponse.success(sequenceService.createStateInvariantPopup(projectId, instanceId));
    }

    @Operation(summary = "弹窗内点击创建按钮创建状态")
    @PostMapping("/clickCreateState")
    public BaseResponse<ModelResultVo> clickCreateState(@RequestBody ClickCreateStateDTO clickCreateStateDto) {
        return BaseResponse.success(sequenceService.clickCreateState(clickCreateStateDto));
    }

    @Operation(summary = "创建状态常量")
    @PostMapping("/createStateInvariant")
    public BaseResponse<ModelResultVo> createStateInvariant(@Valid @RequestBody CreateStateInvariantDTO createStateInvariantDto) {
        return BaseResponse.success(sequenceService.createStateInvariant(createStateInvariantDto));
    }

    @Operation(summary = "拖拽模型到生命线上")
    @PostMapping("/dragElementToLifeLine")
    public BaseResponse<ModelResultVo> dragElementToLifeLine(@RequestBody DragElementToSequenceDiagramDTO dragElementToSequenceDiagramDto) {
        return BaseResponse.success(sequenceService.dragElementToLifeLine(dragElementToSequenceDiagramDto));
    }

    @Operation(summary = "图形图层之间覆盖")
    @PostMapping("/shapeLayerOverlay")
    public BaseResponse<ModelResultVo> shapeLayerOverlay(@Valid @RequestBody ShapeLayerOverlayDTO shapeLayerOverlayDTO) {
        return BaseResponse.success(sequenceService.shapeLayerOverlay(shapeLayerOverlayDTO));
    }

    @Operation(summary = "消息端变更")
    @PostMapping("/messageEndChange")
    public BaseResponse<ModelResultVo> messageEndChange(@Valid @RequestBody MessageEndChangeDTO messageEndChangeDTO) {
        return BaseResponse.success(sequenceService.messageEndChange(messageEndChangeDTO));
    }

    @Operation(summary = "拖拽工具栏生命线到序列图上")
    @PostMapping("/dragToolBarLifelineToSequenceDiagram")
    public BaseResponse<ModelResultVo> dragToolBarLifelineToSequenceDiagram(
            @RequestBody DragToolBarLifeLineWithRoleDto dragDto) {
        return BaseResponse.success(sequenceService.dragToolBarLifelineToSequenceDiagram(dragDto));
    }
}
